package kiang.tei;

import com.jfinal.template.Engine;
import com.jfinal.template.Template;
import com.jfinal.template.source.ClassPathSourceFactory;
import kiang.teb.TebEngine;
import kiang.teb.TebModelGen;
import java.io.OutputStream;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * JFinal Enjoy Template Engine
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public final class Enjoy implements TebEngine {
	
	Engine engine = Engine.use().setSourceFactory(new ClassPathSourceFactory());
	Template template = engine.getTemplate("/kiang/tpl/enjoy.tpl");

    @Override
    public TebEngine init(Properties properties) throws Exception {
        return this;
    }

    @Override
    public void test(Map arguments, Writer writer) throws Exception {
    	template.render(arguments, writer);
	}

    @Override
    public void test(Map arguments, OutputStream output) throws Exception {
    	template.render(arguments, output);
    }

    @Override
    public boolean isBinarySupport() {
        return true;
    }

    @Override
    public void shut() throws Exception {
    }

	public static void main(String args[]) throws Exception {
        String source="UTF-8", target = "UTF-8";
        OutputStream output = System.out;
        Map data = new HashMap();
        data.put("target", target);
        data.put("format", true);
        data.put("models", TebModelGen.dummyModels(20));
        Properties properties = new Properties();
        properties.setProperty("source", source);
        properties.setProperty("target", target);
        properties.setProperty("binary", String.valueOf(true));
        TebEngine engine = new Enjoy().init(properties);
        engine.test(data, output);
        engine.shut();
    }
}


